<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isc="http://extension-functions.intersystems.com" xmlns:hl7="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="isc hl7 xsi exsl">

		
	<!-- 生活方式章节 -->
	<xsl:template match="*" mode="SocialDeterminantSection">
		<xsl:apply-templates select="$sectionRootPath[hl7:code/@displayName=$hcc_SocialDeterminant]" mode="SocialDeterminantEntry">
		</xsl:apply-templates>
	</xsl:template>
	<!-- 生活方式章节条目 -->
	<xsl:template match="*" mode="SocialDeterminantEntry">
	    <!-- only process smorking, drinking and food items -->
		<xsl:apply-templates select="hl7:entry/hl7:observation[(hl7:code/@code='DE03.00.070.00' and hl7:value/@value='true') or (hl7:code/@code='DE03.00.030.00' and hl7:value/@value='true') or hl7:code/@code='DE03.00.080.00']" mode="HCCSocialHistory">
			<xsl:with-param name="sectionType" select="'SD'"/>
		</xsl:apply-templates>
	</xsl:template>	

	
	<!--通用社会史条目输出模板-->
	<xsl:template match="*" mode="HCCSocialHistory">
		<xsl:param name = "sectionType" />
		<xsl:variable name="itemType"><xsl:value-of select="hl7:code/@code"/></xsl:variable>
		<SocialHistory>
			<EncounterNumber><xsl:value-of select="$encompassingEncounterID"/></EncounterNumber>
			<ExternalId><xsl:value-of select="concat($hccDocNo,'-',$sectionType,'-',position())"/></ExternalId>
			<xsl:choose>
		    <!-- 吸烟标志 -->
			<xsl:when test="$itemType='DE03.00.070.00'">
				<SocialHabit>
					<Code><xsl:value-of select="'吸烟'"/></Code>
					<Description><xsl:value-of select="'吸烟'"/></Description>
				</SocialHabit>
				<SocialHabitQty>
					<Code><xsl:value-of select="../../hl7:entry/hl7:observation[hl7:code/@code='DE03.00.053.00']/hl7:value/@value"/></Code>
					<Description><xsl:value-of select="../../hl7:entry/hl7:observation[hl7:code/@code='DE03.00.053.00']/hl7:value/@value"/></Description>
				</SocialHabitQty>
				<SocialHabitCategory>
					<Code><xsl:value-of select="'不良嗜好'"/></Code>
					<Description><xsl:value-of select="'不良嗜好'"/></Description>
				</SocialHabitCategory>
			</xsl:when>
			<!-- 饮酒标志 -->
			<xsl:when test="$itemType='DE03.00.030.00'">
				<SocialHabit>
					<Code><xsl:value-of select="'饮酒'"/></Code>
					<Description><xsl:value-of select="'饮酒'"/></Description>
				</SocialHabit>
				<SocialHabitQty>
					<Code><xsl:value-of select="../../hl7:entry/hl7:observation[hl7:code/@code='DE03.00.054.00']/hl7:value/@value"/></Code>
					<Description><xsl:value-of select="../../hl7:entry/hl7:observation[hl7:code/@code='DE03.00.054.00']/hl7:value/@value"/></Description>
				</SocialHabitQty>
				<SocialHabitCategory>
					<Code><xsl:value-of select="'不良嗜好'"/></Code>
					<Description><xsl:value-of select="'不良嗜好'"/></Description>
				</SocialHabitCategory>
			</xsl:when>
			<!-- 饮食情况 -->
			<xsl:when test="$itemType='DE03.00.080.00'">
				<SocialHabit>
					<Code><xsl:value-of select="'饮食情况'"/></Code>
					<Description><xsl:value-of select="'饮食情况'"/></Description>
				</SocialHabit>
				<SocialHabitQty>
					<Code><xsl:value-of select="hl7:value/@code"/></Code>
					<Description><xsl:value-of select="hl7:value/@displayName"/></Description>
				</SocialHabitQty>
				<SocialHabitCategory>
					<Code><xsl:value-of select="'饮食情况'"/></Code>
					<Description><xsl:value-of select="'饮食情况'"/></Description>
				</SocialHabitCategory>
			</xsl:when>
			</xsl:choose>
		</SocialHistory>		
	</xsl:template>
	
</xsl:stylesheet>
